package cn.cvs.controller;

import com.sun.org.apache.xpath.internal.operations.Mod;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.AbstractController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@Controller
//@RequestMapping(value = "/hello")
public class HelloController extends AbstractController {

    @RequestMapping(value = "/hello")
    public String hello() throws Exception{
        System.out.println("Spring MVC 框架搭建成功！");
        return "hello";
    }

    @RequestMapping(value = "/shangJi3")
    public String shangJi3(Model model, @RequestParam(required = false) String name){
        System.out.println(name);
        model.addAttribute("name",name);
        return "shangJi3-show";
    }

    @RequestMapping(value = "jianDa-show")
    public String addUser(Model model,@RequestParam(required = false) int id ,@RequestParam(required = false) String modelNum ,@RequestParam(required = false) double price ,@RequestParam(required = false) String date ){
        model.addAttribute("id",id);
        model.addAttribute("modelNum",modelNum);
        model.addAttribute("price",price);
        model.addAttribute("date",date);
        return "jianDa-show";
    }

    /**
     * 重写父类方法
     * @return
     * @throws Exception
     */
    @Override
    protected ModelAndView handleRequestInternal(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws Exception {

        System.out.println("Spring MVC框架搭建成功!");

        return new ModelAndView("hello");
    }

}
